<template>
    <div class="toTop" v-show="flg" @click="click">
        <img src="@/assets/images/icon/shang.png" alt="">
    </div>
</template>

<script>
export default {
    data:function(){
        return {
            flg:false
        }
    },
    created:function(){
        window.addEventListener('scroll',() => {
            let scrollTop = document.body.scrollTop || document.documentElement.scrollTop
            if(scrollTop >= 100){
                this.flg = true
            } else {
                this.flg = false
            }
        })
    },
    methods:{
        click:function(){
            console.log('点击')
            document.body.scrollTop = 0
            document.documentElement.scrollTop = 0

        }
    }
}
</script>

<style lang="less" scoped>
    .toTop{
        width: 38px;
        height: 38px;
        line-height: 38px;
        border-radius: 50%;
        position: fixed;
        border: 1px solid rgb(135,137,147);
        // background: red;
        position: fixed;
        bottom: 80px;
        right: 9px;
        z-index: 8;

        img{
            width: 38px;
        }
    }
</style>